package com.bidevalution.business.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bidevalution.business.context.SysIdentityCode;
import com.bidevalution.business.service.BeSysIdentityService;
import com.bidevalution.dao.entity.BeSysIdentity;
import com.bidevalution.dao.mapper.BeSysIdentityMapper;
@Service
public class BeSysIdentityServiceImpl implements BeSysIdentityService {
	@Autowired
	private BeSysIdentityMapper beSysIdentityMapper;

	@Transactional
	@Override
	public String getValue(SysIdentityCode code) {
		synchronized (this) {
			BeSysIdentity beSysIdentity = beSysIdentityMapper.selectByPrimaryKey(code.getCode());
			if (beSysIdentity != null) {
				Integer indentityValue = 0;
				if (beSysIdentity.getIdentityValue() == null) {
					indentityValue = 1;
				} else {
					indentityValue = beSysIdentity.getIdentityValue() + 1;

				}
				beSysIdentity.setIdentityValue(indentityValue);
				beSysIdentityMapper.updateByPrimaryKey(beSysIdentity);
				return String.valueOf(indentityValue);
			}
			return null;
		}
		
	}

}
